import Cookies from 'js-cookie'

//后端携带请求头headers的token的键key
const TokenKey = 'user_token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function clearToken() {
  // 获取所有cookie的键名
  let cookies = document.cookie.split(";");
  
  // 遍历每个cookie键名并删除它们
  cookies.forEach(function(cookie) {
      let eqPos = cookie.indexOf("=");
      let name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
      Cookies.remove(name.trim(), { path: '' }); // 使用空路径确保删除所有路径下的cookie
  });
}